/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-12-06 07:07:35
 * @LastEditors: GGB
 * @LastEditTime: 2021-12-07 10:28:03
 */
import axios from 'axios';
// axios.create({
//     baseURL: process.env.baseUrl, // url = base url + request url
//     //携带证书
//     withCredentials: true, // send cookies when cross-domain requests
//     //设置超时时间
//     timeout: 5000 // request timeout
// })
axios.defaults.baseURL = process.env.baseUrl
axios.defaults.withCredentials = true
axios.defaults.timeout = 5000

export default {
    //get请求
    requestGet(url, params = {}) {
        console.log(process.env.baseUrl)
        return new Promise((resolve, reject) => {
            axios.get(url, params).then(res => {
                resolve(res.data)
            }).catch(error => {
                reject(error)
            })
        })
    },

    // post请求
    requestPost(url, params = {}) {
        return new Promise((resolve, reject) => {
            axios.post(url, params).then(res => {
                resolve(res.data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    // delete请求
    requestDelete(url, params = {}) {
        return new Promise((resolve, reject) => {
            axios.delete(url, params).then(res => {
                resolve(res.data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    // put请求
    requestPut(url, params = {}) {
        return new Promise((resolve, reject) => {
            axios.put(url, params).then(res => {
                resolve(res.data)
            }).catch(error => {
                reject(error)
            })
        })
    }
}
